home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7976 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.lang.c,comp.lang.c++,comp.os.ms-windows.programmer.misc,comp.os.msdos.programmer,comp.programming,comp.windows.ms.programmer
  2. Path: txnews.amd.com!news
  3. From: Clark Archer <carcher@f25mail.amd.com>
  4. Subject: Re: Date Arithmetic
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <3124A458.7BF8@f25mail.amd.com>
  7. Sender: news@txnews.amd.com
  8. Nntp-Posting-Host: graywolf
  9. Content-Transfer-Encoding: 7bit
  10. Organization: Advanced Micro Devices, Inc.
  11. References: <4g19kp$640@tracy.protocom.com>
  12. Mime-Version: 1.0
  13. Date: Fri, 16 Feb 1996 15:35:52 GMT
  14. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  15.  
  16. Michael J. Karas wrote:
  17. > I am working on an algorithm for a laser marking machine that writes
  18. > expiration delays on to food product boxes. The algorithm needs to
  19. > be able to add NNN days to todays date in the fastest manner possible
  20. > without using any floating point arithmetic. I could use help from anyone
  21. > that has C code for doing this. It would be nice if the solution took the
  22. > leap year problem in to account including the special case of the year
  23. > 2000. Thanks in advance to anyone who could share their knowledge on this
  24. > subject.
  25. > -----
  26. > Michael Karas             | EMail: mkaras@pclink.com
  27. > Carousel Design Solutions | America OnLine: MJKaras
  28. > 6021 Logan Avenue South   | Voice: (612) 861-1284
  29. > Minneapolis MN 55419      | Fax:   (612) 861-1386
  30. > -----
  31.  
  32. You could use the C runtime library function time() to get the current 
  33. time and then add NNN * SECS_PER_DAY to it and then convert back to a 
  34. struct tm like:
  35.     
  36.     #define SECS_PER_DAY  86400
  37.  
  38.     time_t tmtNow;
  39.     struct tm tmThen;
  40.  
  41.     tmtNow = time(NULL);
  42.     tmtNow += (nDaysToAdd * SECS_PER_DAY);
  43.     tmThen = *localtime(tmtNow);
  44.  
  45.  
  46. Then you can examine the contents of the tmThen struct to get 
  47. month/day/year info. 
  48.  
  49. NOTE: This may not account correctly for daylight savings time.
  50.  
  51. Clark
  52.